//! @Author: DengLibin 榆霖
//! @Date:  2022-06-30 16:19:32
//! @Description: 连接池 文档： https://crates.io/crates/mysql



use std::{sync::Arc, time::Duration};

use mysql::{Pool, OptsBuilder};




/// @Author: DengLibin 榆霖
/// @Date:  2022-06-30 16:20:55
/// @Description: 初始化连接池
/// 
pub fn create_conn_pool()->Result<Pool, Box<dyn std::error::Error>>{
    let opts = OptsBuilder::new()
    .user(Some("denglibin"))
    .pass(Some("denglibin"))
    .ip_or_hostname(Some("192.168.56.104"))
    .tcp_port(3307)
    .tcp_connect_timeout(Some(Duration::from_secs(60)))
    .db_name(Some("doc_file_sys"));

    //let p = Pool::new("mysql://denglibin:denglibin@192.168.56.101:3307/doc_file_sys")?;
    let p = Pool::new(opts)?;
    info!("获取数据库连接池成功");
    return Ok(p);
}

/// @Author: DengLibin 榆霖
/// @Date:  2022-06-30 16:20:55
/// @Description: 初始化连接池
/// 
pub fn get_conn_pool()->Result<Arc<Pool>, Box<dyn std::error::Error>>{

    let p = create_conn_pool()?;
    return Ok(Arc::new(p));
}